﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Touch2Like.Model;
using Newtonsoft.Json.Linq;
using System.Data;

namespace Touch2Like.Web.api
{
    public partial class login : System.Web.UI.Page
    {
        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    Response.Clear();

        //    Touch2Like.DAL.UserDAL user = new Touch2Like.DAL.UserDAL();
        //    UserInfo info = user.GetByUserName(Request["username"].Trim());

        //    JObject jo = new JObject();

        //    if (info != null)
        //    {
        //        string token = WebUtility.GetMD5String(info.UserName + ":" + Utility.Encryption.Decrypt(info.Password));

        //        if (Request["password"].Trim() == Utility.Encryption.Decrypt(info.Password))
        //        {
        //            jo["success"] = "yes";
        //            jo["token"] = token;

        //            JObject msg = new JObject();
        //            Touch2Like.DAL.Tag tag = new Touch2Like.DAL.Tag();

        //            DataTable dtTag = tag.GetByCustomer(info.UserID.Value);
        //            msg["tagcount"] = dtTag.Rows.Count;

        //            JArray tagArray = new JArray();
        //            for (int i = 0; i < dtTag.Rows.Count && i < 10; i++)
        //            {
        //                JObject tagObject = new JObject();

        //                tagObject["taguid"] = dtTag.Rows[i]["taguid"].ToString();
        //                tagObject["alias"] = dtTag.Rows[i]["alias"].ToString();
        //                tagObject["serviceurl"] = dtTag.Rows[i]["serviceurl"].ToString();

        //                tagArray.Add(tagObject);
        //            }

        //            msg["tags"] = tagArray;

        //            msg["userinfo"] = new JObject();
        //            msg["userinfo"]["userid"] = info.UserID;
        //            msg["userinfo"]["username"] = info.UserName;
        //            msg["userinfo"]["email"] = info.Email;

        //            jo["msg"] = msg;
        //        }
        //        else
        //        {
        //            jo["success"] = "no";
        //            jo["token"] = "null";
        //            jo["msg"] = "user failed";
        //        }
        //    }
        //    else
        //    {
        //        jo["success"] = "no";
        //        jo["token"] = "null";
        //        jo["msg"] = "user failed";
        //    }

        //    Response.Write(jo.ToString());

        //    Response.End();
        //}
    }
}